package {{folderName}}

{{#alloperations}}
import (
	"github.com/gophercloud/gophercloud"{{#hasQueryPagin}}
	"github.com/gophercloud/gophercloud/pagination"{{/hasQueryPagin}}
{{#operations}}
{{#imports}}	"{{import}}"
{{/imports}}
)
{{/operations}}
{{/alloperations}}
{{#alloperations}}
{{#operations}}
{{#operation}}
{{#hasBodyParam}}
{{#bodyParam.vendorExtensions.x-reqbodyparaminnermodel}}

type {{vendorExtensions.x-nickname}}Opts {{#bodyParam.isListContainer}}{{#bodyParams}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{/bodyParams}}{{/bodyParam.isListContainer}}{{^bodyParam.isListContainer}} struct {
{{#bodyParams}}
	{{vendorExtensions.x-exportParamName}}{{name}} {{#vendorExtensions.x-isPointer}}*{{/vendorExtensions.x-isPointer}}{{{dataType}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"{{#required}} required:"true"{{/required}}`
{{/bodyParams}}
}{{/bodyParam.isListContainer}}
{{/bodyParam.vendorExtensions.x-reqbodyparaminnermodel}}
{{/hasBodyParam}}
{{#hasQueryParams}}

type {{vendorExtensions.x-nickname}}Opts struct {
{{#queryParams}}
{{#description}}
    // {{{description}}}
{{/description}}
    {{vendorExtensions.x-exportParamName}} {{{dataType}}} `q:"{{baseName}}{{#required}},required{{/required}}"`
{{/queryParams}}
}
{{/hasQueryParams}}
{{/operation}}
{{/operations}}
{{/alloperations}}
{{#allmodels}}
{{#model}}
{{#isReq}}
{{#isEnum}}

{{#description}}
	// {{{classname}}} : {{{description}}}
{{/description}}
type {{{classname}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{/format}}
// List of {{{name}}}
const (
	{{#allowableValues}}
	{{#enumVars}}
	{{^-first}}
	{{/-first}}
	{{name}} {{{classname}}} = "{{{value}}}"
	{{/enumVars}}
	{{/allowableValues}}
)
{{/isEnum}}
{{^isEnum}}

{{#description}}
// {{{description}}}
{{/description}}
type {{^isreqfirstmodel}}{{classname}}{{/isreqfirstmodel}}{{#isreqfirstmodel}}{{vendorExtensions.x-nickname}}Opts{{/isreqfirstmodel}} struct {
{{#vars}}
{{^-first}}
{{/-first}}
{{#description}}
	// {{{description}}}
{{/description}}
	{{name}} {{#vendorExtensions.x-isPointer}}*{{/vendorExtensions.x-isPointer}}{{{datatype}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"{{#required}} required:"true"{{/required}}{{#withXml}} xml:"{{baseName}}"{{/withXml}}`
{{/vars}}
}
{{/isEnum}}
{{/isReq}}
{{/model}}
{{/allmodels}}
{{#alloperations}}
{{#operations}}
{{#operation}}
{{#hasParams}}
{{#hasBodyParam}}
{{#bodyParam.isListContainer}}

func (opts {{{bodyParam.items.items.datatype}}}) ToMap() (map[string]interface{}, error) {
	return gophercloud.BuildRequestBody(opts, "")
}
{{/bodyParam.isListContainer}}

func (opts {{vendorExtensions.x-nickname}}Opts) To{{vendorExtensions.x-nickname}}Map() ({{#bodyParam.isListContainer}}[]{{/bodyParam.isListContainer}}map[string]interface{}, error) {
    {{#bodyParam.isListContainer}}
    newOpts := make([]map[string]interface{}, len(opts))
    for i, opt := range opts {
        opt, err := opt.ToMap()
        if err != nil {
            return nil, err
        }
        newOpts[i] = opt
    }
    return newOpts, nil
    {{/bodyParam.isListContainer}}
    {{^bodyParam.isListContainer}}
	return gophercloud.BuildRequestBody(opts, "")
	{{/bodyParam.isListContainer}}
}
{{/hasBodyParam}}
{{/hasParams}}
{{/operation}}
{{/operations}}
{{/alloperations}}
{{#alloperations}}
{{#operations}}
{{#operation}}
{{#hasParams}}
{{#hasBodyParam}}

type {{vendorExtensions.x-nickname}}OptsBuilder interface {
	To{{vendorExtensions.x-nickname}}Map() ({{#bodyParam.isListContainer}}[]{{/bodyParam.isListContainer}}map[string]interface{}, error)
}
{{/hasBodyParam}}
{{/hasParams}}
{{/operation}}
{{/operations}}
{{/alloperations}}
{{#alloperations}}
{{#operations}}
{{#operation}}

func {{vendorExtensions.x-nickname}}(client *gophercloud.ServiceClient{{#hasPathParams}}{{#pathParams}}{{^vendorExtensions.x-isProject}}, {{{paramName}}} {{{dataType}}}{{/vendorExtensions.x-isProject}}{{/pathParams}}{{/hasPathParams}}{{#hasQueryParams}}, opts {{vendorExtensions.x-nickname}}Opts{{/hasQueryParams}}{{#hasBodyParam}}, opts {{vendorExtensions.x-nickname}}OptsBuilder{{/hasBodyParam}}) {{^vendorExtensions.x-isPage}}(r {{vendorExtensions.x-nickname}}Result) {{/vendorExtensions.x-isPage}}{{#vendorExtensions.x-isPage}}pagination.Pager {{/vendorExtensions.x-isPage}}{
{{#hasQueryParams}}
    q, err := gophercloud.BuildQueryString(&opts)
{{/hasQueryParams}}
{{#vendorExtensions.x-isPage}}
    if err != nil {
        return pagination.Pager{Err: err}
    }
{{/vendorExtensions.x-isPage}}
{{^vendorExtensions.x-isPage}}
{{#hasQueryParams}}
    if err != nil {
        r.Err = err
        return
    }
{{/hasQueryParams}}
{{/vendorExtensions.x-isPage}}
{{#hasQueryParams}}
    url := {{vendorExtensions.x-nicknameLowerCase}}URL(client) + q.String()
{{/hasQueryParams}}
{{#vendorExtensions.x-isPage}}
    return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
        return {{vendorExtensions.x-classname}}Page{pagination.LinkedPageBase{PageResult: r}}
    })
{{/vendorExtensions.x-isPage}}
{{#hasBodyParam}}
    b, err := opts.To{{vendorExtensions.x-nickname}}Map()
    if err != nil {
        r.Err = err
        return
    }

{{/hasBodyParam}}
{{^vendorExtensions.x-isPage}}
    _, r.Err = client.{{httpMethod}}({{#hasQueryParams}}url{{/hasQueryParams}}{{^hasQueryParams}}{{vendorExtensions.x-nicknameLowerCase}}URL(client{{#hasPathParams}}{{#pathParams}}{{^vendorExtensions.x-isProject}}, {{{paramName}}}{{/vendorExtensions.x-isProject}}{{/pathParams}}{{/hasPathParams}}){{/hasQueryParams}}{{#hasBodyParam}}, b{{/hasBodyParam}}{{^vendorExtensions.x-is-delete-method}}, &r.Body{{/vendorExtensions.x-is-delete-method}}, &gophercloud.RequestOpts{
        OkCodes: []int{{#responses}}{{#isDefault}}{{=<% %>=}}{<% code %>}<%={{ }}=%>{{/isDefault}}{{/responses}},
    })

    return
{{/vendorExtensions.x-isPage}}
}
{{/operation}}
{{/operations}}
{{/alloperations}}